<?php


namespace Biz\model\advertisement;

use util\UserHelper;

class MPositionAdType extends MBaseDbModel
{
    const _CONFIG_FILE_ = 'db_position';

    const _CONFIG_SELECT_ = 'db_position';

    const _DATABASE_ = 'hhz_position';

    const _TABLE_NAME = 'position_ad_type';

    const STATUS_NORMAL = 1;

    public static $normalCondition = [
        'type_status' => self::STATUS_NORMAL,
        'ORDER' => [
            'sort' => 'DESC',
            'id' => 'ASC'
        ],
    ];

    public static function getAllPosition2Cron()
    {
        return self::select('*', [
            'type_status' => self::STATUS_NORMAL,
            'ORDER' => [
                'sort' => 'DESC',
                'id' => 'ASC'
            ],
        ]);
    }

    public static function getAllPosition()
    {
        $where = [
            'type_status' => self::STATUS_NORMAL,
            'ORDER' => [
                'sort' => 'DESC',
                'id' => 'ASC'
            ],
        ];

        if (!UserHelper::isSuperAdmin()) {
            $adTypeIds = MHhzDepartmentAdType::getValidAdTypesByDepartmentId(UserHelper::getDepartmentId());
            $where['id'] = $adTypeIds;
        }

        return self::select("*", $where);
    }

    public static function getById($id)
    {
        if (!$id) {
            return [];
        }
        $where = [
            'id' => $id
        ];
        return self::get("*", $where);
    }
}
